expenseSchema.pre(ꞌsaveꞌ)   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 10
loc 10
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A ��) 3 3 1
1 View Code Duplication
var mongoose = require('mongoose')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
var expenseItem = require('./common/line-item')
3
4
var expenseSchema = new mongoose.Schema({
5
  date: { type: Date, default: Date.now },
6
  company: { type: mongoose.Schema.Types.ObjectId, ref: 'Company', required: true },
7
  category: ['Purchases', 'Motor Fuel', 'Motor Serv/Repair',
8
    'Motor Tax/Ins', 'Van DOE', 'Public Laibility Insurance',
9
    'Advertising', 'Tele/bband', 'Training', 'Office Expenses',
10
    'Sub Contractor', 'Landfill', 'Ber Cert Fees', 'Bank Fees',
11
    'Sundry', 'Heating', 'Sponsorship', 'Equipment Hire', 'Electricity'],
12
  items: [expenseItem],
13
  totalVat: { type: Number, default: 0.00 },
14
  totalExVat: { type: Number, default: 0.00 },
15
  total: { type: Number, default: 0.00 }
16
})
17
18
expenseSchema.pre('save', function (next) {
19
  let overallTotal = 0.00
20
    // All the items should give the total
21
  this.items.forEach(function (item) {
22
    overallTotal = overallTotal + item.total
23
  })
24
25
  this.total = overallTotal
26
  next()
27
})
28
29
module.exports = mongoose.model('Expense', expenseSchema)
30